package com.zz.controller;


import com.zz.pojo.Student;
import com.zz.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/student")

public class StudentController {

    @Autowired
    @Qualifier("StudentServiceImpl")
    private StudentService studentService;


    @RequestMapping("/allStudent")
    public String listStudent(Model model){
        List<Student> list=studentService.queryAllStudent();
        model.addAttribute("list", list);
        return "student/allStudent";
    }

    @RequestMapping("/toAddStudent")
    public String toAddPaper() {
        return "student/addStudent";
    }

    @RequestMapping("/addStudent")
    public String addPaper(Student student) {
        System.out.println(student);
        studentService.addStudent(student);
        return "redirect:/student/allStudent";
    }


    @RequestMapping("/toUpdateStudent")
    public String updateStudent(Model model,int id){
        Student student = studentService.queryStudentById(id);
        System.out.println(student);
        model.addAttribute("student",student );
        return "student/updateStudent";
    }

    @RequestMapping("/updateStudent")

    public String updateBook(Model model,Student student){
        System.out.println(student);
        studentService.updateStudent(student);
        Student student1=studentService.queryStudentById(student.getId());
        model.addAttribute(student1);
        return "redirect:/student/allStudent";
    }

    //删除
    @RequestMapping("/del/{StudentId}")
    public String deleteStudent(@PathVariable("StudentId") int id) {
        studentService.deleteStudentById(id);
        return "redirect:/student/allStudent";
    }
}
